package com.gy.springboot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.gy.springboot.dao.EmployeeDao;
import com.gy.springboot.entity.Department;
import com.gy.springboot.entity.Employee;
import com.gy.springboot.mapper.DepartmentMapper;
import com.gy.springboot.service.DepartmentService;

@RestController
public class DeptController {

    @Autowired
    DepartmentMapper departmentMapper;

    @Autowired
    EmployeeDao employeeDao;

    @Autowired
    private DepartmentService departmentService;

    @GetMapping("/get/emp/{id}")
    public Employee getEmp(@PathVariable("id") Integer id) {
        return employeeDao.getEmpById(id);
    }

    @GetMapping("/dept/get/{id}")
    public Department getDepartment(@PathVariable("id") Integer id) {
        return departmentMapper.getDepById(id);
    }

    @GetMapping("/add/dept")
    public Department addDept(Department department) {
        departmentMapper.insertDept(department);
        return department;
    }

    @GetMapping("find/dept/{id}")
    public Department findADept(@PathVariable("id") Integer id) {
        return departmentService.findDepById(id);
    }

    @GetMapping("update/dept")
    public Department updateEmp(Department department) {
        return departmentService.updateEmp(department);
    }

    @GetMapping("/dept/remove/{id}")
    public String removeDept(@PathVariable("id") Integer id) {
        departmentService.deleteDept(id);
        return "Success";
    }

    @GetMapping("get/dept/deptName/{deptName}")
    public Department findADeptByDeptName(
            @PathVariable("deptName") String deptName) {
        return departmentService.getDeptByDeptName(deptName);
    }

}
